package com.bloggers;

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.bloggers.model.Book;
import com.bloggers.util.HibernateUtil;

public class HibernateTest
{

	public static void main(String[] args)
	{
		HibernateTest hibernateTest = new HibernateTest();

		/* creating a new book object */
		Book book = new Book();
		book.setBookId(1);
		book.setDate(new Date());
		book.setBookName("Hibernate in action");

		/* saving the book object */
		hibernateTest.saveBook(book);

	}

	public void saveBook(Book book)
	{
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();

		/* saving the book object here */
		session.save(book);
		session.getTransaction().commit();
	}

}
